/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calcclient2;

import com.mycompany.remotecalc.ICalculatorBeanRemote;
import com.mycompany.remotecalc.ICapitalBeanRemote;
import java.util.ResourceBundle;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author nico
 */
public class CalcClient2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Hello World!");
        
        System.out.println(getWelcomeMessage());
        
        try {
            InitialContext context = new InitialContext();

            String name = "java:global/remoteCalc/CapitalBean";
            String name2 = "java:global/remoteCalc/CalculatorBean";

            ICapitalBeanRemote bean =
                    (ICapitalBeanRemote) context.lookup(name);

            ICalculatorBeanRemote calcBean =
                    (ICalculatorBeanRemote) context.lookup(name2);

            System.out.println(bean.getCapital("India"));
            System.out.println(bean.getCapital("Japan"));
            System.out.println(calcBean.add(3.3, 3));

            System.out.println(calcBean.getValueCalc());

        } catch (javax.naming.NoInitialContextException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

    public static String getWelcomeMessage() {

        final ResourceBundle resourceBundle = ResourceBundle.
                      getBundle("resources.messages");

        final String message = resourceBundle.getString("welcome");

        return message;

    }
}
